import django
from django.conf import settings
from django.conf.urls.defaults import *
from django.contrib import admin
import registration

from ce_atlas_app.views import *

admin.autodiscover()

urlpatterns = patterns('',

    url(r'^$', 
        index),
    url(r'^get_media', 
        get_media),
    url(r'^get_user_uploaded_shapes', 
        get_user_uploaded_shapes),
    url(r'^delete_media/(\d+)/$', 
        delete_media),
    url(r'^get_wms_layers', 
        get_wms_layers),
    url(r'^get_wfs_layers', 
        get_wfs_layers), 
    url(r'^get_layer_data/(.*)', 
        get_layer_data), 
    url(r'^upload_media', 
        upload_media),
    url(r'^upload_shape_file', 
        upload_shape_file),
    url(r'^rectified-image/(.*)', 
        get_rectified_wms_image),
    url(r'^jsmin/', 
        jsmin),
    url(r'^getfonts/$', 
        get_fonts),
    url(r'^favicon\.ico$',
        'django.views.generic.simple.redirect_to',
        {'url': '/media/img/favicon.ico'})
)

if hasattr(registration,'backends'):
    urlpatterns += patterns('',
                            url(r'^accounts/', include('registration.backends.default.urls')),
                            url(r'^admin/(.*)', admin.site.root))
else :
    urlpatterns += patterns('',
                            url(r'^admin/', include(admin.site.urls)),
                            url(r'^accounts/', include('registration.urls')))

urlpatterns += patterns('',
    url(r'^accounts/login/$',
        auth_views.login,
        name='auth_login'),
       
    url(r'^accounts/logout/$',
        auth_views.logout,
        {'template_name': 'accounts/logout.html'},
        name='auth_logout'),
        
    url(r'^accounts/profile/$',
        'django.views.generic.simple.redirect_to',
        {'url': '/'}),
    url(r'^favicon\.ico$',
        'django.views.generic.simple.redirect_to',
        {'url': '/media/img/favicon.ico'})
)

if True:
    urlpatterns += patterns('',
    
        (r'^media/(.*)$',
            'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),    
            
        (r'^data/(.*)$',
            'django.views.static.serve',
            {'document_root': settings.USER_DATA, 'show_indexes': True}),
            
        (r'^projects/ce_atlas/(.*)$',
            'django.views.static.serve',
            {'document_root': settings.DATA_ROOT, 'show_indexes': True}),
            
        (r'^projects/livingatlas/(.*)$',
            'django.views.static.serve',
            {'document_root': settings.DATA_ROOT, 'show_indexes': True}),
            
    )
